//
//  Home_ZP_01View.m
//  MagicBox
//
//  Created by dllo on 16/8/10.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Home_ZP_01View.h"

#import "HomePage.h"
#import "Home_ZP_01TableviewCell.h"
#import "Home_ZP_02TableViewCell.h"
#import "Home_ZP_03TableViewCell.h"
#import "Home_ZP_04TableViewCell.h"
#import "HomePage_HobbyViewController.h"
@interface Home_ZP_01View()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, retain) NSMutableArray *oneArray;

@property (nonatomic, retain) UITableView *bigTabview;
@property (nonatomic, retain) NSDictionary *liftDic;
@property (nonatomic, retain) NSDictionary *rightDic;
@property (nonatomic, retain) NSMutableArray *guessArr;
@property (nonatomic, retain) NSMutableArray *nameArray;


@end


@implementation Home_ZP_01View
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor redColor];
        self.oneArray = [NSMutableArray array];
        self.liftDic = [NSDictionary dictionary];
        self.rightDic = [NSDictionary dictionary];
        self.guessArr = [NSMutableArray array];
        self.nameArray = [NSMutableArray array];
        
        
    }
    return self;
    
    
}
-(void)setMuArr:(NSMutableArray *)muArr{
    _muArr = muArr;
    
    self.oneArray = _muArr;
      [self creactbigtabview];
}
-(void)setDicLeft:(NSDictionary *)dicLeft{
    _dicLeft = dicLeft;
    self.liftDic = _dicLeft;

}
-(void)setDicRight:(NSDictionary *)dicRight{
    _dicRight = dicRight;
    
    self.rightDic = _dicRight;

}

-(void)setGueArr:(NSMutableArray *)gueArr{
    _gueArr = gueArr;
    
    self.guessArr = gueArr;
    
}
-(void)setNameArr:(NSMutableArray *)nameArr{
    _nameArr = nameArr;
    self.nameArray = _nameArr;
    
    
    
}




-(void)creactbigtabview{
    self.bigTabview = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    self.bigTabview.backgroundColor= [UIColor redColor];
    self.bigTabview.delegate = self;
    self.bigTabview.dataSource = self;

    
    [self addSubview:self.bigTabview];
    
    [self.bigTabview registerClass:[Home_ZP_01TableviewCell class] forCellReuseIdentifier:@"bigCell"];
    [self.bigTabview registerClass:[Home_ZP_02TableViewCell class] forCellReuseIdentifier:@"headCell"];
    [self.bigTabview registerClass:[Home_ZP_03TableViewCell class] forCellReuseIdentifier:@"oneCell"];
    [self.bigTabview registerClass:[Home_ZP_04TableViewCell class] forCellReuseIdentifier:@"twoCell"];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
            return 1;
            break;
        case 2:
            return 1;
            break;
        case 3:
            return self.guessArr.count;
            break;
    }
    return 0;
    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
       
        {


            Home_ZP_01TableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bigCell"];
            cell.muArr = self.oneArray;
   
            return cell;

        }
            break;
            
        case 1:
        {
            Home_ZP_02TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"headCell"];
         

            cell.onedic = self.liftDic;
            cell.twodic = self.rightDic;
            return cell;
            
        }
            break;
        case 2:
        {
            Home_ZP_04TableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"twoCell"];
            cell.muArray = self.nameArray;
        
            return cell;
            
        }
            break;
            
        case 3:
        {
            Home_ZP_03TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"oneCell"];
            cell.model = [self.guessArr objectAtIndex:indexPath.row];
            return cell;
            
        }
            break;
    }
   
    return 0;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return SCREENHEIGHT/4;
            break;
        case 1:
            return SCREENHEIGHT/6;
            break;
        case 2:
            return SCREENHEIGHT/4;
            
            break;
        case 3:
            return SCREENHEIGHT/9;
            break;
    }
    return 0;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 3){
        HomePage_HobbyViewController *hhvc =[[HomePage_HobbyViewController alloc]init];
        hhvc.model = [self.guessArr objectAtIndex:indexPath.row];

        [[self navigatuibController]pushViewController:hhvc animated:YES];
        
    }
    
    
    
    
}

-(UINavigationController*)navigatuibController{
    for (UIView* next = [self superview];next ; next = next.superview){
        UIResponder *nextResponder = [next nextResponder];
        if([nextResponder isKindOfClass:[UINavigationController class]]){
            return (UINavigationController*)nextResponder;
        }
    }
    
    
        return nil;
    

}












/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
